package algorithms.leecode;

public class Au50 {
    public static void main(String[] args) {
        System.err.println(myPow(2, -2147483648));
    }

    public static double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }

        long i = (long) n;
        if (n < 0) {
            return  1/ww(x, -i,true);
        } else {
            return ww(x, i,false);
        }

    }

    public static double ww(double x, long n,boolean k) {
        if (x > 100000 && k) {
            return 100000;
        }

        long lef = n % 2;
        long mu = n / 2;
        double xl = x * lef;
        if (xl == 0 || n == 1) {
            xl = 1;
        }
        if (mu > 0) {
            x *= x;
            return ww(x, mu,k) * xl;
        } else {
            return xl * x;
        }
    }
}
